import { pipe, of, map, Observer } from 'rxjs';

export function instantFunc(func: () => void) {
    return of(null).pipe(map(_ => func()));
}

export function NullNextAndCompleteFunc(observer: Observer<null>) {
    return () => {
        observer.next(null);
        observer.complete();
    }
}

export function TransparentPass(observer: Observer<null>): Partial<Observer<never>> {
    return {
        next: _ => observer.next(_),
        error: err => observer.error(err),
        complete: () => observer.complete(),
    }
}

export function Log(logFunc: (message?: any, ...optionalParams: any[]) => void, logTag = ''): Partial<Observer<never>> {
    return {
        next: _ => logFunc(`${logTag} @next:`, _),
        error: err => logFunc(`${logTag} @error:`, err),
        complete: () => logFunc(`${logTag} @complete`),
    }
}